﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;

using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.Data;
using DevExpress.Web.ASPxEditors;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;
using LMD.Lib.Controls;

public partial class UFTGuest : ICPRelationshipPage
{
    public UFTData m_uftData = new UFTData();
    public int m_iEventId = 0;
    public int iCheckSubmit = 0;
    
    #region Properties
    public String m_sxEventId
    {
        get
        {
            if (!String.IsNullOrEmpty(Request.QueryString["eid"]))
            {
                return Request.QueryString["eid"];
            }
            else
            {
                return String.Empty;
            }
        }
    }
    #endregion Properties

    #region Event Handlers
    protected override void Page_Load(object sender, EventArgs e)
    {
        m_lsPermittedRoles.Add(ICPUserRole.CAR);
        base.Page_Load(sender, e);
        Page.Title = "ICP Lintasarta: Relationship, Invite Guest";
        m_iEventId = Context.ReadInt("eid");
        if (!IsPostBack && !IsCallback)
        {
            InitUFTData();
            Session[KSession.UFT_FILTERTEMA] = null;
            Session[KSession.UFT_GUEST] = null;
        }
        InitGuestInvitation();
        InitGuestInvitation2();
        InitGuest();
    }
    protected void dgGuestList_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if (e.Parameters.ToUpper().StartsWith("REJECT"))
        {
            //RejectInvitation(e.Parameters);
        }
        else if (e.Parameters.ToUpper().Equals("SUBMIT"))
        {
            //SubmitGuest(e.Parameters);
            InitGuestInvitation();
            dgGuestList.Columns["INVITE"].Visible = false;
        }
        else
        {
            InitGuestInvitation();
        }
        
    }
    protected void cbkInvite_Callback(object sender, CallbackEventArgs e)
    {
        System.Threading.Thread.Sleep(KGlobal.AJAX_WAIT_TIME);
        e.Result = HandleInvitation(e.Parameter);
    }
    protected void dgGuest_Invitation_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if (e.Parameters.StartsWith("FILTER"))
        {
            HandleFilter(e.Parameters);
        }
        else if (e.Parameters.StartsWith("ALL"))
        {
            Session[KSession.UFT_FILTERTEMA] = null;
            InitGuestInvitation();
            InitGuestInvitation2();
        }
        else
        {
            MoveToSelectedGrid();
        }
    }
    protected void dgGuest_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        HandleGuest(e.Parameters);
    }
    protected void dgGuestSelected_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if(e.Parameters.ToUpper().StartsWith("INIT"))
        {
            InitSelectedGuest(e.Parameters);
        }
        else if(e.Parameters.ToUpper().StartsWith("SELECT"))
        {
            HandleSelectGuest(e.Parameters);
        }
    }
	protected void btnExport_Click(object sender, EventArgs e)
    {
        DataTable dt = DBQuery.EventTable.GetEventDataByID(m_iEventId);
        String sxFilename = String.Format("Guest List {0} ({1})", dt.Rows[0]["CODE"].ToString(), dt.Rows[0]["EVENT_DATE"].ToString());
        dgExporter.WriteXlsToResponse(sxFilename);
    }
    #endregion Event Handlers

    #region Custom Methods
    protected override void DoSearch(String sxSearchQuery)
    {
        throw new NotImplementedException();
    }
    private void InitUFTData()
    {
        if (m_iEventId > 0)
        {
            DataTable dtEventTable = DBQuery.EventTable.GetEventDataByID(m_iEventId);
            m_uftData.sxCode = dtEventTable.Rows[0]["CODE"].ToString();
            m_uftData.dtmEventDate = Convert.ToDateTime(dtEventTable.Rows[0]["EVENT_DATE"]);
            m_uftData.iEventId = Convert.ToInt32(dtEventTable.Rows[0]["P_EVENT_ID"]);
            if (dtEventTable.Rows[0]["INVITATION_ATTACHMENT_ID"] == DBNull.Value)
            {
                m_uftData.iInvitationAttachmentId = 0;
            }
            else
            {
                m_uftData.iInvitationAttachmentId = Convert.ToInt32(dtEventTable.Rows[0]["INVITATION_ATTACHMENT_ID"]);
            }
            if (dtEventTable.Rows[0]["EVENT_ATTACHMENT_ID"] == DBNull.Value)
            {
                m_uftData.iEventAttachmentId = 0;
            }
            else
            {
                m_uftData.iEventAttachmentId = Convert.ToInt32(dtEventTable.Rows[0]["EVENT_ATTACHMENT_ID"]);
            }
            if (dtEventTable.Rows[0]["PRESENTATION_ID"] == DBNull.Value)
            {
                m_uftData.iPresentationId = 0;
            }
            else
            {
                m_uftData.iPresentationId = Convert.ToInt32(dtEventTable.Rows[0]["PRESENTATION_ID"]);
            }
            m_uftData.sxLocation = dtEventTable.Rows[0]["LOCATION"].ToString();
            m_uftData.dtmStartTime = Convert.ToDateTime(dtEventTable.Rows[0]["START_TIME"]);
            m_uftData.dtmEndTime = Convert.ToDateTime(dtEventTable.Rows[0]["END_TIME"]);
            m_uftData.BuildFieldSet_UFTData();
        }
    }
    private void InitGuestInvitation()
    {
        String sxCARID = ICPUser.ID;
        DataTable dtSelected = DBQuery.CustomerTable.GetCustomerInvitation(m_iEventId, sxCARID);

        dgGuestList.DataSource = dtSelected;
		//disini buat nampilin yg selection
        for (int i = 0; i < dtSelected.Rows.Count; i++)
        {
            dgGuestList.Selection.SetSelectionByKey(
                dtSelected.Rows[i]["T_RELATION_INVITATION_ID"],
                dtSelected.Rows[i]["STATUS_SEND_MAIL"].ToString() == "Y");

            //dgGuestList.Selection.SetSelection(i, dtSelected.Rows[i]["STATUS_SEND_MAIL"].ToString() == "Y");
        }
        //
        dgGuestList.DataBind();
        dgGuestList.Columns["CUSTOMER_ID"].Visible = false;
        iCheckSubmit = DBQuery.CustomerTable.CheckGuestSubmitted(m_iEventId.ToString());
        if (iCheckSubmit > 0)
        {
            dgGuestList.Columns["INVITE"].Visible = false;
            //dgGuestList.Columns["ALASAN_REJECT"].Visible = false;
            dgGuestList.Columns["REJECT"].Visible = false;
        }
    }

    private void InitGuest()
    {
        if (Session[KSession.UFT_GUEST] != null)
        {
            int iCompanyId = Convert.ToInt32(Session[KSession.UFT_GUEST]);
            Cached.ContactPersonTable cachedCP = new Cached.ContactPersonTable();
            DataTable dtCP = cachedCP.GetContactPersonList(iCompanyId);
            dgGuest.DataSource = dtCP;
            dgGuest.DataBind();
        }
    }
    private void InitSelectedGuest(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        int iCompanyId = Convert.ToInt32(sxSplitted[2]);
        int iInvitationId = Convert.ToInt32(sxSplitted[1]);
        DataTable dtExistingGuest = DBQuery.CustomerTable.getExistingGuest2(iInvitationId);
        dgGuestSelected.DataSource = dtExistingGuest;
        dgGuestSelected.DataBind();
    }
    private void HandleGuest(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        int iCompanyId = Convert.ToInt32(sxSplitted[2]);
        Session[KSession.UFT_GUEST] = iCompanyId;
        InitGuest();
    }
    private void HandleSelectGuest(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        int iInvId = Convert.ToInt32(sxSplitted[1]);
        DBLib dbl = new DBLib();
        dbl.BeginTransaction();
        try
        {
            DataTable dtGuest = (DataTable)dgGuest.DataSource;
            List<object> keyValues = dgGuest.GetSelectedFieldValues("ID_COMBINED");
            foreach (object obj in keyValues)
            {
                String[] sxIDSplitted = obj.ToString().Split('_');
                bool IsNewCP = sxIDSplitted[1].ToUpper() == KGlobal.YES;
                int iCPId = Convert.ToInt32(sxIDSplitted[0]);
                GuestData guestData = new GuestData();
                if (IsNewCP)
                {
                    guestData.iNewCPId = iCPId;
                }
                else
                {
                    guestData.iCPId = iCPId;
                }
                guestData.sxCreatedBy = ICPUser.ID;
                guestData.iInvitationId = iInvId;
                DBQuery.CustomerTable.SaveGuest(dbl, guestData);
                guestData = null;
            }
            dbl.EndTransaction(true);
            InitSelectedGuest("INIT" + KGlobal.DELIMITER + sxSplitted[1] + KGlobal.DELIMITER + sxSplitted[2]);
        }
        catch (Exception ex)
        {
            dbl.EndTransaction(false);
            throw ex;
        }
    }

    private string HandleInvitation(string sxParam)
    {
        String[] sxSplitted = sxParam.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);

        String sxOutput = String.Empty;
        String sxCompanyId = String.Empty;
        //int iCustId = 0; 
        String sxCompanyName = String.Empty;
        String sxInvitationId = String.Empty; 
        //int iInvitationId = 0; 
        DataTable dtExistingGuest = new DataTable(); 
		String sxEmailType;// = sxSplitted[1].ToUpper();
		
        switch (sxSplitted[0].ToUpper())
        {
            //case "INVITE":
            //    sxCompanyId = sxSplitted[1];
            //    iCustId = int.Parse(sxSplitted[1]);
            //    sxCompanyName = DBQuery.CustomerTable.GetCompanyNameByID(iCustId);
            //    sxInvitationId = sxSplitted[2];
            //    iInvitationId = Convert.ToInt32(sxInvitationId);
            //    dtExistingGuest = DBQuery.CustomerTable.getExistingGuest(iInvitationId);
            //    sxOutput = UFTManager.BuildEditor_GuestInvitation(sxCompanyId, KLOV.Generic.CONTACTPERSON,
            //        sxInvitationId, sxCompanyId, sxCompanyName, dtExistingGuest);
            //    break;
            //case "MORE":
            //    sxCompanyId = sxSplitted[1];
            //    int iGuestCount = Convert.ToInt32(sxSplitted[3]);
            //    sxOutput = CustomControls.BuildEditor_ComboBoxAndText(sxCompanyId + "_" + iGuestCount.ToString(), 
            //        KLOV.Generic.CONTACTPERSON, KControl.INPUT_ID, null, null, null, TextboxType.Empty, sxCompanyId);
            //    break;
            //case "SAVE":
            //    sxInvitationId = sxSplitted[2];
            //    iInvitationId = Convert.ToInt32(sxInvitationId);
            //    dtExistingGuest = DBQuery.CustomerTable.getExistingGuest(iInvitationId);
            //    sxOutput = saveGuest(sxSplitted, dtExistingGuest);
            //    break;
            case "REJECT":
                sxInvitationId = sxSplitted[1];
                sxCompanyId = sxSplitted[2];
                sxOutput = UFTManager.BuildEditor_Reason(sxInvitationId, sxCompanyId);
                break;
            case "EMAIL":
                //sxInvitationId = sxSplitted[2];
                sxOutput = UFTManager.BuildEditor_EmailType("0");
                break;
            case "SUBMIT":
            //case "SENDEMAIL":
                //SubmitGuest(sxParam);
                //SendEmail(sxParam);
                sxEmailType = sxSplitted[1].ToUpper();
                if (sxEmailType.Equals("NOTSEND"))
                {
                    SubmitGuestWithoutEmail(sxParam);
                }
                else
                {
                    SendEmail(sxParam);
                }
                break;
            case "NOTSEND":
                SubmitGuestWithoutEmail(sxParam);
                break;
            case "REASONSUBMIT":
                int iInvID = Convert.ToInt32(sxSplitted[1]);
                int iReasonId = Convert.ToInt32(sxSplitted[2]);
                int iCompanyId = Convert.ToInt32(sxSplitted[3]);
                RejectInvitation(iInvID, iReasonId, iCompanyId);
                break;
        }

        return sxOutput;
    }
    private void RejectInvitation(int iInvId, int iReasonId, int iCompanyId)
    {
        //String[] sxSplitted = sxParam.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        //String sxReason = sxSplitted[2].ToString();
        //int iInvID = Convert.ToInt32(sxSplitted[1]);

        DBLib dbl = new DBLib();
        dbl.BeginTransaction();
        try
        {
            DBQuery.CustomerTable.DeleteGuest(dbl, iInvId.ToString());
            DBQuery.CustomerTable.RejectInvitation(dbl, iInvId, iReasonId);
            DBQuery.CustomerTable.Blacklist(dbl, Convert.ToInt32(m_sxEventId), iCompanyId, iReasonId);
            //bikin lagi query buat insert ke T_EVENT_BLACKLIST
            dbl.EndTransaction(true);
        }
        catch (Exception ex)
        {
            // ROLLBACK
            dbl.EndTransaction(false);
            throw ex;
        }
        InitGuestInvitation();
    }

    //private String saveGuest(String[] sxSplitted, DataTable dtExistingGuest)
    //{
    //    String sxReturn = String.Empty;
    //    String sxInvitationId = sxSplitted[2];
    //    List<int> lsNewIds = new List<int>();
        
    //    DBLib dbl = new DBLib();
    //    dbl.BeginTransaction();
        
    //    try
    //    {
    //        //' BIKIN DELETE SEMUA GUEST YG INVITATION ID-nya = sxINvId
    //        DBQuery.CustomerTable.DeleteGuest(dbl, sxInvitationId);

    //        for (int i = sxSplitted.Length - (sxSplitted.Length - 3); i < sxSplitted.Length; i++)
    //        {
    //            String[] sxRowSplitted = sxSplitted[i].Split(
    //                new String[] { KGlobal.NEWLINE }, StringSplitOptions.None);

    //            if (String.IsNullOrEmpty(sxRowSplitted[1]))
    //                continue;

    //            String[] sxIDSplitted = sxRowSplitted[1].Split('_');
    //            bool IsNewCP = sxIDSplitted[1].ToUpper() == KGlobal.YES;

    //            int iCPId = Convert.ToInt32(sxIDSplitted[0]);

    //            /* CHECK IF NEW DATA CONTAINS SOME RECURRENCES */
    //            if (lsNewIds.Contains(iCPId))
    //                continue;
                
    //            GuestData guestData = new GuestData();
    //            if (IsNewCP)
    //            {
    //                guestData.iNewCPId = iCPId;
    //            }
    //            else
    //            {
    //                guestData.iCPId = iCPId;
    //            }
    //            guestData.sxCreatedBy = ICPUser.ID;
    //            guestData.iInvitationId = Convert.ToInt32(sxInvitationId);
    //            DBQuery.CustomerTable.SaveGuest(dbl, guestData);
        
    //            lsNewIds.Add(iCPId);
    //        }


    //        // COMMIT 
    //        dbl.EndTransaction(true);
    //    }
    //    catch (Exception ex)
    //    {
    //        //ROLLBACK
    //        dbl.EndTransaction(false);
    //        throw ex;
    //    }
        
    //    return sxReturn;
    //}

    private void SubmitGuest(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        String sxEmailType = sxSplitted[1];
        DataTable dtGuest = (DataTable)dgGuestList.DataSource;
        //List<UFTMailData> lstUFTMailData = new List<UFTMailData>();
        
        DBLib dbl = new DBLib();
        dbl.BeginTransaction();
        try
        {
            DataTable dtEventTable = DBQuery.EventTable.GetEventDataByID(m_iEventId);
            DateTime dtmEventDate = Convert.ToDateTime(dtEventTable.Rows[0]["EVENT_DATE"]);

            //int iUserEventId = DBQuery.NotificationTable.InsertNotification_UserEvent(dbl, m_iEventId.ToString(),
            //    ICPUser.ID, -1, UserEventType.UserForum, dtmEventDate);

            List<int> lsCustId = new List<int>();

            for (int i = 0; i < dgGuestList.VisibleRowCount; i++)
            {
                String sxInvId = dtGuest.Rows[i]["T_RELATION_INVITATION_ID"].ToString();
                String sxStatusReject = dtGuest.Rows[i]["STATUS_REJECT"].ToString();
                if (sxStatusReject.Equals("T"))
                {
                    DBQuery.CustomerTable.SubmitGuest(dbl, sxInvId);
                    //disini taro code buat ambil email data
                    if (!sxEmailType.ToUpper().Equals("NOTSEND"))
                    {
                        DataTable dtMailData = DBQuery.CustomerTable.GetEmailData(dbl, sxInvId);

                        for (int x = 0; x < dtMailData.Rows.Count; x++)
                        {
                            if (!String.IsNullOrEmpty(dtMailData.Rows[x]["EMAIL"].ToString()))
                            {
                                String sxPhysicalFilename = String.Empty;
                                String sxPath = String.Empty;

                                UFTMailData uftMailData = new UFTMailData();
                                uftMailData.iInvitationID = Convert.ToInt32(dtMailData.Rows[x]["T_RELATION_INVITATION_ID"]);
                                uftMailData.sxContactName = dtMailData.Rows[x]["NAME"].ToString();
                                uftMailData.sxEmail = dtMailData.Rows[x]["EMAIL"].ToString();
                                uftMailData.sxCode = dtMailData.Rows[x]["CODE"].ToString();
                                uftMailData.sxEvent = dtMailData.Rows[x]["EVENT"].ToString();
                                uftMailData.dtmEventDate = Convert.ToDateTime(dtMailData.Rows[x]["EVENT_DATE"]);
                                uftMailData.dtmStartTime = Convert.ToDateTime(dtMailData.Rows[x]["START_TIME"]);
                                uftMailData.dtmEndTime = Convert.ToDateTime(dtMailData.Rows[x]["END_TIME"]);
                                uftMailData.sxLocation = dtMailData.Rows[x]["LOCATION"].ToString();
                                uftMailData.iInvAttachmentID = Convert.ToInt32(dtMailData.Rows[x]["INVITATION_ATTACHMENT_ID"]);
                                uftMailData.sxInvAttachmentName = dtMailData.Rows[x]["ORIGINAL_FILENAME"].ToString();
                                sxPhysicalFilename = dtMailData.Rows[x]["PHYSICAL_FILENAME"].ToString();
                                sxPath = dtMailData.Rows[x]["PATH"].ToString();
                                uftMailData.sxInvAttachmentPath =
                                    System.Web.HttpContext.Current.Server.MapPath(
                                    "~/" + sxPath + "/" + sxPhysicalFilename);

                                SendMailExample(uftMailData, sxEmailType);
                                //lstUFTMailData.Add(uftMailData);
                            }

                        }
                        //foreach (UFTMailData umData in lstUFTMailData)
                        //{
                        //    SendMailExample(umData, sxEmailType);
                        //}
                    }
                    int iCustId = Convert.ToInt32(dtGuest.Rows[i]["CUSTOMER_ID"]);
                    lsCustId.Add(iCustId);
                    //DBQuery.NotificationTable.InsertNotification_MapByEvent(dbl, iUserEventId, iCustId);
                }
            }

            int iUserEventId = DBQuery.NotificationTable.InsertNotification_UserEvent(dbl, m_iEventId.ToString(),
                ICPUser.ID, -1, UserEventType.UserForum, dtmEventDate);

            foreach (int iCustomerId in lsCustId)
            {
                DBQuery.NotificationTable.InsertNotification_MapByEvent(dbl, iUserEventId, iCustomerId);
            }
            //==============disini untuk email assman
            //1. ambil data event by m_sxEventId 
            //EventMailData eventMail = new EventMailData();
            m_iEventId = Convert.ToInt32(m_sxEventId);
            DataTable dtEventMail = DBQuery.EventTable.GetEventDataForEmail(m_iEventId);
            //2. ambil CAR&CP event by m_sxEventId masukin ke dt
            DataTable dtCARandCP = DBQuery.EventTable.GetCARAndCPForEmail(m_iEventId);
            String sxCurrentCARId = String.Empty;
            String sxPrevCARId = String.Empty;
            List<CARandCPforEmail> lsCARandCP = new List<CARandCPforEmail>();
            CARandCPforEmail CARandCP;// = new CARandCPforEmail();
            //3. dtCARandCP di looping cek dulu id CAR nya
            foreach (DataRow drCARandCP in dtCARandCP.Rows)
            {
                sxCurrentCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                if (!sxPrevCARId.Equals(sxCurrentCARId))
                {
                    if (String.IsNullOrEmpty(sxPrevCARId))
                    {
                        //data pertama
                        //masukin data ke class
                        CARandCP = new CARandCPforEmail();
                        CARandCP.sxCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                        CARandCP.sxCAR = drCARandCP["CAR_NAME"].ToString();
                        CARandCP.sxContactName = drCARandCP["NAME"].ToString();
                        CARandCP.iCustomerId = Convert.ToInt32(drCARandCP["CUSTOMER_ID"]);
                        CARandCP.sxCompanyName = drCARandCP["COMPANY_NAME"].ToString();
                        CARandCP.iInvitationId = Convert.ToInt32(drCARandCP["T_RELATION_INVITATION_ID"]);
                        lsCARandCP.Add(CARandCP);
                        sxPrevCARId = sxCurrentCARId;
                    }
                    else
                    {
                        //kirim email
                        SendEmailAssMan(dtEventMail, lsCARandCP, sxPrevCARId);
                        //clear list
                        lsCARandCP.Clear();
                        //masukin data lagi ke list
                        CARandCP = new CARandCPforEmail();
                        CARandCP.sxCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                        CARandCP.sxCAR = drCARandCP["CAR_NAME"].ToString();
                        CARandCP.sxContactName = drCARandCP["NAME"].ToString();
                        CARandCP.iCustomerId = Convert.ToInt32(drCARandCP["CUSTOMER_ID"]);
                        CARandCP.sxCompanyName = drCARandCP["COMPANY_NAME"].ToString();
                        CARandCP.iInvitationId = Convert.ToInt32(drCARandCP["T_RELATION_INVITATION_ID"]);
                        lsCARandCP.Add(CARandCP);
                        sxPrevCARId = sxCurrentCARId;
                    }
                }
                else
                {
                    //CAR masih sama
                    //masukin data ke class
                    CARandCP = new CARandCPforEmail();
                    CARandCP.sxCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                    CARandCP.sxCAR = drCARandCP["CAR_NAME"].ToString();
                    CARandCP.sxContactName = drCARandCP["NAME"].ToString();
                    CARandCP.iCustomerId = Convert.ToInt32(drCARandCP["CUSTOMER_ID"]);
                    CARandCP.sxCompanyName = drCARandCP["COMPANY_NAME"].ToString();
                    CARandCP.iInvitationId = Convert.ToInt32(drCARandCP["T_RELATION_INVITATION_ID"]);
                    lsCARandCP.Add(CARandCP);
                    sxPrevCARId = sxCurrentCARId;
                }
            }
            if (lsCARandCP.Count > 0)
            {
                //kirim email data CAR yang terakhir
                SendEmailAssMan(dtEventMail, lsCARandCP, sxPrevCARId);
            }

            //==============
            
            dbl.EndTransaction(true);
        }
        catch (Exception ex)
        {
            // ROLLBACK
            dbl.EndTransaction(false);
            throw ex;
        }
    }

	private void SendEmail(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        String sxEmailType = sxSplitted[1];
        DataTable dtOld = DBQuery.CustomerTable.GetCustomerInvitation(m_iEventId, ICPUser.ID);
        DataTable dtGuest = (DataTable)dgGuestList.DataSource;
        //List<UFTMailData> lstUFTMailData = new List<UFTMailData>();

        //DBLib dbl = new DBLib();
        //dbl.BeginTransaction();
        try
        {
            DataTable dtEventTable = DBQuery.EventTable.GetEventDataByID(m_iEventId);
            DateTime dtmEventDate = Convert.ToDateTime(dtEventTable.Rows[0]["EVENT_DATE"]);

            //int iUserEventId = DBQuery.NotificationTable.InsertNotification_UserEvent(dbl, m_iEventId.ToString(),
            //    ICPUser.ID, -1, UserEventType.UserForum, dtmEventDate);

            List<int> lsCustId = new List<int>();

            for (int i = 0; i < dgGuestList.VisibleRowCount; i++)
            {
                String sxInvId = dtGuest.Rows[i]["T_RELATION_INVITATION_ID"].ToString();
                String sxStatusReject = dtGuest.Rows[i]["STATUS_REJECT"].ToString();
                String sxStatusSendEmail = dtGuest.Rows[i]["STATUS_SEND_MAIL"].ToString();
                bool IsOldSelected = dtOld.Rows[i]["STATUS_SEND_MAIL"].ToString() == KGlobal.YES;
                bool IsNewSelected = dgGuestList.Selection.IsRowSelectedByKey(dtOld.Rows[i]["T_RELATION_INVITATION_ID"]);
                //bool IsSelected = dgGuestList.Selection.IsRowSelected(i);
                //if (IsOldSelected && !IsNewSelected)
                //{
                //    DBQuery.FeedSubscriptionTable.DeleteFeedSubscription(dbl, iFeedSourceId, m_iUserRoleId);
                //}
                //else if (!IsOldSelected && IsNewSelected)
                //{
                //    DBQuery.FeedSubscriptionTable.AddFeedSubscription(dbl, iFeedSourceId, m_iUserRoleId);
                //}
                if (sxStatusReject.Equals("T") && !IsOldSelected && IsNewSelected)
                {
                    DBQuery.CustomerTable.UpdateStatusSendEmailGuest(sxInvId);
                    //disini taro code buat ambil email data
                    if (!sxEmailType.ToUpper().Equals("NOTSEND"))
                    {
                        DataTable dtMailData = DBQuery.CustomerTable.GetEmailData(sxInvId);

                        for (int x = 0; x < dtMailData.Rows.Count; x++)
                        {
                            if (!String.IsNullOrEmpty(dtMailData.Rows[x]["EMAIL"].ToString()))
                            {
                                String sxPhysicalFilename = String.Empty;
                                String sxPath = String.Empty;

                                UFTMailData uftMailData = new UFTMailData();
                                uftMailData.iInvitationID = Convert.ToInt32(dtMailData.Rows[x]["T_RELATION_INVITATION_ID"]);
                                uftMailData.sxContactName = dtMailData.Rows[x]["NAME"].ToString();
                                uftMailData.sxEmail = dtMailData.Rows[x]["EMAIL"].ToString();
                                uftMailData.sxCode = dtMailData.Rows[x]["CODE"].ToString();
                                uftMailData.sxEvent = dtMailData.Rows[x]["EVENT"].ToString();
                                uftMailData.dtmEventDate = Convert.ToDateTime(dtMailData.Rows[x]["EVENT_DATE"]);
                                uftMailData.dtmStartTime = Convert.ToDateTime(dtMailData.Rows[x]["START_TIME"]);
                                uftMailData.dtmEndTime = Convert.ToDateTime(dtMailData.Rows[x]["END_TIME"]);
                                uftMailData.sxLocation = dtMailData.Rows[x]["LOCATION"].ToString();
                                uftMailData.iInvAttachmentID = Convert.ToInt32(dtMailData.Rows[x]["INVITATION_ATTACHMENT_ID"]);
                                uftMailData.sxInvAttachmentName = dtMailData.Rows[x]["ORIGINAL_FILENAME"].ToString();
                                sxPhysicalFilename = dtMailData.Rows[x]["PHYSICAL_FILENAME"].ToString();
                                sxPath = dtMailData.Rows[x]["PATH"].ToString();
                                uftMailData.sxInvAttachmentPath =
                                    System.Web.HttpContext.Current.Server.MapPath(
                                    "~/" + sxPath + "/" + sxPhysicalFilename);

                                SendMailExample(uftMailData, sxEmailType);
                                //lstUFTMailData.Add(uftMailData);
                            }

                        }
                        //foreach (UFTMailData umData in lstUFTMailData)
                        //{
                        //    SendMailExample(umData, sxEmailType);
                        //}
                    }
                    int iCustId = Convert.ToInt32(dtGuest.Rows[i]["CUSTOMER_ID"]);
                    lsCustId.Add(iCustId);
                    //DBQuery.NotificationTable.InsertNotification_MapByEvent(dbl, iUserEventId, iCustId);
                }
            }

            //int iUserEventId = DBQuery.NotificationTable.InsertNotification_UserEvent(dbl, m_iEventId.ToString(),
            //    ICPUser.ID, -1, UserEventType.UserForum, dtmEventDate);

            //foreach (int iCustomerId in lsCustId)
            //{
            //    DBQuery.NotificationTable.InsertNotification_MapByEvent(dbl, iUserEventId, iCustomerId);
            //}
/*			
            //==============disini untuk email assman
            //1. ambil data event by m_sxEventId 
            //EventMailData eventMail = new EventMailData();
            m_iEventId = Convert.ToInt32(m_sxEventId);
            DataTable dtEventMail = DBQuery.EventTable.GetEventDataForEmail(m_iEventId);
            //2. ambil CAR&CP event by m_sxEventId masukin ke dt
            DataTable dtCARandCP = DBQuery.EventTable.GetCARAndCPForEmail(m_iEventId);
            String sxCurrentCARId = String.Empty;
            String sxPrevCARId = String.Empty;
            List<CARandCPforEmail> lsCARandCP = new List<CARandCPforEmail>();
            CARandCPforEmail CARandCP;// = new CARandCPforEmail();
            //3. dtCARandCP di looping cek dulu id CAR nya
            foreach (DataRow drCARandCP in dtCARandCP.Rows)
            {
                sxCurrentCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                if (!sxPrevCARId.Equals(sxCurrentCARId))
                {
                    if (String.IsNullOrEmpty(sxPrevCARId))
                    {
                        //data pertama
                        //masukin data ke class
                        CARandCP = new CARandCPforEmail();
                        CARandCP.sxCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                        CARandCP.sxCAR = drCARandCP["CAR_NAME"].ToString();
                        CARandCP.sxContactName = drCARandCP["NAME"].ToString();
                        CARandCP.iCustomerId = Convert.ToInt32(drCARandCP["CUSTOMER_ID"]);
                        CARandCP.sxCompanyName = drCARandCP["COMPANY_NAME"].ToString();
                        CARandCP.iInvitationId = Convert.ToInt32(drCARandCP["T_RELATION_INVITATION_ID"]);
                        lsCARandCP.Add(CARandCP);
                        sxPrevCARId = sxCurrentCARId;
                    }
                    else
                    {
                        //kirim email
                        SendEmailAssMan(dtEventMail, lsCARandCP, sxPrevCARId);
                        //clear list
                        lsCARandCP.Clear();
                        //masukin data lagi ke list
                        CARandCP = new CARandCPforEmail();
                        CARandCP.sxCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                        CARandCP.sxCAR = drCARandCP["CAR_NAME"].ToString();
                        CARandCP.sxContactName = drCARandCP["NAME"].ToString();
                        CARandCP.iCustomerId = Convert.ToInt32(drCARandCP["CUSTOMER_ID"]);
                        CARandCP.sxCompanyName = drCARandCP["COMPANY_NAME"].ToString();
                        CARandCP.iInvitationId = Convert.ToInt32(drCARandCP["T_RELATION_INVITATION_ID"]);
                        lsCARandCP.Add(CARandCP);
                        sxPrevCARId = sxCurrentCARId;
                    }
                }
                else
                {
                    //CAR masih sama
                    //masukin data ke class
                    CARandCP = new CARandCPforEmail();
                    CARandCP.sxCARId = drCARandCP["CAR_EMPLOYEE_NO"].ToString();
                    CARandCP.sxCAR = drCARandCP["CAR_NAME"].ToString();
                    CARandCP.sxContactName = drCARandCP["NAME"].ToString();
                    CARandCP.iCustomerId = Convert.ToInt32(drCARandCP["CUSTOMER_ID"]);
                    CARandCP.sxCompanyName = drCARandCP["COMPANY_NAME"].ToString();
                    CARandCP.iInvitationId = Convert.ToInt32(drCARandCP["T_RELATION_INVITATION_ID"]);
                    lsCARandCP.Add(CARandCP);
                    sxPrevCARId = sxCurrentCARId;
                }
            }
            if (lsCARandCP.Count > 0)
            {
                //kirim email data CAR yang terakhir
                SendEmailAssMan(dtEventMail, lsCARandCP, sxPrevCARId);
            }
*/
            //==============

            //dbl.EndTransaction(true);
        }
        catch (Exception ex)
        {
            // ROLLBACK
            //dbl.EndTransaction(false);
            throw ex;
        }
    }

    private void SubmitGuestWithoutEmail(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        String sxEmailType = sxSplitted[1];
        DataTable dtGuest = (DataTable)dgGuestList.DataSource;
        //List<UFTMailData> lstUFTMailData = new List<UFTMailData>();

        DBLib dbl = new DBLib();
        dbl.BeginTransaction();
        try
        {
            DataTable dtEventTable = DBQuery.EventTable.GetEventDataByID(m_iEventId);
            DateTime dtmEventDate = Convert.ToDateTime(dtEventTable.Rows[0]["EVENT_DATE"]);

            //int iUserEventId = DBQuery.NotificationTable.InsertNotification_UserEvent(dbl, m_iEventId.ToString(),
            //    ICPUser.ID, -1, UserEventType.UserForum, dtmEventDate);

            List<int> lsCustId = new List<int>();

            for (int i = 0; i < dgGuestList.VisibleRowCount; i++)
            {
                String sxInvId = dtGuest.Rows[i]["T_RELATION_INVITATION_ID"].ToString();
                String sxStatusReject = dtGuest.Rows[i]["STATUS_REJECT"].ToString();
                if (sxStatusReject.Equals("T"))
                {
                    DBQuery.CustomerTable.SubmitGuest(dbl, sxInvId);
                    int iCustId = Convert.ToInt32(dtGuest.Rows[i]["CUSTOMER_ID"]);
                    lsCustId.Add(iCustId);
                    //DBQuery.NotificationTable.InsertNotification_MapByEvent(dbl, iUserEventId, iCustId);
                }
            }

            int iUserEventId = DBQuery.NotificationTable.InsertNotification_UserEvent(dbl, m_iEventId.ToString(),
                ICPUser.ID, -1, UserEventType.UserForum, dtmEventDate);

            foreach (int iCustomerId in lsCustId)
            {
                DBQuery.NotificationTable.InsertNotification_MapByEvent(dbl, iUserEventId, iCustomerId);
            }

            dbl.EndTransaction(true);
        }
        catch (Exception ex)
        {
            // ROLLBACK
            dbl.EndTransaction(false);
            throw ex;
        }
    }
	
	private void SendEmailAssMan(DataTable dtEventMail, List<CARandCPforEmail> lsCARandCP, String sxPrevCARId)
    {
        if (!String.IsNullOrEmpty(sxPrevCARId))
        {
            DataTable dtAssManEmail = DBQuery.EventTable.GetAssManForEmail(Convert.ToInt32(sxPrevCARId));
            foreach (DataRow drAssManEmail in dtAssManEmail.Rows)
            {
                String sxSender = DBQuery.EmailSenderTable.GetRecentEmail();
                Mailer mail = new Mailer();
                //mail.EmailSender = new System.Net.Mail.MailAddress("donot-reply@icp.lintasarta.co.id", "ICP Bots");
                mail.EmailSender = new System.Net.Mail.MailAddress(sxSender);
                mail.EmailSubject = dtEventMail.Rows[0]["EVENT"].ToString() + " : " + dtEventMail.Rows[0]["CODE"].ToString();
                //mail.AddRecipient("diyani.janwir@lintasarta.co.id");
				//mail.AddRecipient("rinawati.daulay@lintasarta.co.id");
				//mail.AddRecipient("yoseph.yusnaedi@lintasarta.co.id");
				//mail.AddRecipient("arief@lintasmediadanawa.com");
				//mail.AddRecipient("diw@lintasarta.co.id");
				//mail.AddRecipient("anggita@lintasmediadanawa.com");
				//mail.AddRecipient("nova@lintasmediadanawa.com");
                mail.AddRecipient(drAssManEmail["EMAIL"].ToString());
                mail.AddCC("forum@lintasarta.co.id");
				mail.AddBCC("bayuardi.rahmanto@lintasarta.co.id");
				//mail.AddBCC("indri.lestiawati@lintasarta.co.id");
                mail.EmailHTMLBody = drAssManEmail["EMAIL"].ToString() + UFTManager.Build_HTMLMailAssManBody(dtEventMail, lsCARandCP);
                mail.EmailPlainText = drAssManEmail["EMAIL"].ToString() + UFTManager.Build_PlainMailAssManBody(dtEventMail, lsCARandCP);
                //mail.SendMail();
            }
        }
    }
    private void HandleFilter(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        int iFilterEventId = Convert.ToInt32(sxSplitted[1]);
        Session[KSession.UFT_FILTERTEMA] = iFilterEventId;
        InitGuestInvitation();
        InitGuestInvitation2();
    }
    protected void InitGuestInvitation2()
    {
        ReloadUnselectedGrid(false);

        GridViewCommandColumn x = new GridViewCommandColumn();
        x.Caption = "#";
        x.ShowSelectCheckbox = true;
        x.VisibleIndex = 0;
        x.Width = 25;
        x.Name = "x";

        GridViewColumnCollection dgc = dgCustomerList.Columns;
        if (dgc.IndexOf(dgCustomerList.Columns["x"]) < 0)
        {
            //dgCustomerList.Columns.Insert(0, x);
            dgCustomerList.Columns.Add(x);
        }

        dgCustomerList.Columns["CUSTOMER_ID"].Visible = false;
        DataTable dt = (DataTable)dgCustomerList.DataSource;
        foreach (DataColumn dc in dt.Columns)
        {
            if (dc.DataType == typeof(DateTime))
            {
                ((GridViewDataDateColumn)dgCustomerList.Columns[dc.ColumnName]).PropertiesDateEdit.DisplayFormatString = "dd-MMM-yyyy";
            }
        }
        GridViewDataTextColumn companyCol = new GridViewDataTextColumn();
        companyCol.DataItemTemplate = new CompanyTemplate(); // Create a template
        companyCol.Name = "COMPANY";
        companyCol.Caption = "COMPANY";
        companyCol.FieldName = "COMPANY_NAME";
        companyCol.VisibleIndex = 1;
        GridViewColumnCollection dgc2 = dgCustomerList.Columns;
        if (dgc2.IndexOf(dgCustomerList.Columns["COMPANY"]) < 0)
        {
            //dgCustomerList.Columns.Insert(1, companyCol);
            dgCustomerList.Columns.Add(companyCol);
        }
        dgCustomerList.Columns["COMPANY_NAME"].Visible = false;
    }
    private void MoveToSelectedGrid()
    {
        DataTable dtSelected = (DataTable)dgGuestList.DataSource;
        List<int> lsCustIdSelected = new List<int>();
        foreach (DataRow dr in dtSelected.Rows)
        {
            lsCustIdSelected.Add(Convert.ToInt32(dr["CUSTOMER_ID"]));
        }
        List<object> keyValues = dgCustomerList.GetSelectedFieldValues("CUSTOMER_ID");

        // BEGIN TRANSACTION
        DBLib dbl = new DBLib();
        dbl.BeginTransaction();
        try
        {
            foreach (object obj in keyValues)
            {
                if (lsCustIdSelected.Contains(Convert.ToInt32(obj)))
                {
                    //Kalau sudah ada di selected grid ga perlu dipindah
                    continue;
                }
                else
                {
                    // INSERT TIAP ROW KE DB
                    InvitationData invData = new InvitationData();
                    invData.intCustID = Convert.ToInt32(obj);
                    invData.intEventID = m_iEventId;
                    invData.sxStatusLain = null;

                    DBQuery.CustomerTable.SaveInvitation(dbl, invData);
                }
            }

            // COMMIT 
            dbl.EndTransaction(true);
        }
        catch (Exception ex)
        {
            // ROLLBACK
            dbl.EndTransaction(false);
            throw ex;
        }
        DBLib dbl2 = new DBLib();
        dbl2.BeginTransaction();
        try
        {
            DBQuery.CustomerTable.UpdateStatusInvitation(dbl2, m_iEventId);
            GetCPTeknisAsGuest(lsCustIdSelected,dbl2);
            //COMMIT
            dbl2.EndTransaction(true);
        }
        catch (Exception ex)
        {
            //ROLLBACK
            dbl2.EndTransaction(false);
            throw ex;
        }
        dgCustomerList.Selection.UnselectAll();
    }
    private void GetCPTeknisAsGuest(List<int> lsCustIdSelected, DBLib dbl)
    {
        //SAVE CPTeknis as Guest by default
        //ambil invID, custID by eventId
        DataTable dtInvitation = DBQuery.CustomerTable.GetInvitationByEventId(m_iEventId);
        //ambil getCPTeknisByCustId
        List<GuestData> lsGuestData = new List<GuestData>();
        GuestData guestData;
        foreach (DataRow dr in dtInvitation.Rows)
        {
            int iCustId = Convert.ToInt32(dr["CUSTOMER_ID"]);
            if (lsCustIdSelected.Contains(iCustId))
            {
                //Kalau sudah ada ga perlu ditambah
                continue;
            }
            else
            {
                object[] objCPTeknis = DBQuery.CustomerTable.getCPTeknisByCustId(iCustId);
                //assign guestData(CPID, invID)
                if (objCPTeknis != null)
                {
                    foreach (object obj in objCPTeknis)
                    {
                        guestData = new GuestData();
                        guestData.iCPId = Convert.ToInt32(obj);
                        guestData.iInvitationId = Convert.ToInt32(dr["T_RELATION_INVITATION_ID"]);
                        guestData.sxCreatedBy = ICPUser.ID;
                        lsGuestData.Add(guestData);
                        guestData = null;
                    }
                }
                else
                {
                    continue;
                }
            }
        }
        //DBLib dbl = new DBLib();
        //dbl.BeginTransaction();
        //try
        //{
        foreach (GuestData guest in lsGuestData)
        {
            //saveGuest(guestData)
            DBQuery.CustomerTable.SaveGuest(dbl, guest);
        }
        //COMMIT
        //    dbl.EndTransaction(true);
        //}
        //catch (Exception ex)
        //{
        //ROLLBACK
        //    dbl.EndTransaction(false);
        //    throw ex;
        //}
    }
    private void ReloadUnselectedGrid(bool bRefresh)
    {
        int iFilterEventId = -1;
        if (Session[KSession.UFT_FILTERTEMA] != null)
        {
            iFilterEventId = Convert.ToInt32(Session[KSession.UFT_FILTERTEMA]);
            bRefresh = true;
        }

        Cached.CustomerTable tblCustomer = new Cached.CustomerTable();
        DataTable dtUnselected = tblCustomer.GetCustomer(m_iEventId, false, iFilterEventId, bRefresh);

        dgCustomerList.DataSource = dtUnselected;
        dgCustomerList.DataBind();
        if (iFilterEventId < 0)
        {
            //dgCustomerList.Columns["T_RELATION_EVENT_ID"].Visible = false;
            dgCustomerList.Columns["CODE"].Visible = false;
            dgCustomerList.Columns["IS_INVITED"].Visible = false;
            dgCustomerList.Columns["IS_ATTENDED"].Visible = false;
            dgCustomerList.Columns["IS_CONFIRMED"].Visible = false;
            dgCustomerList.Columns["IS_BLACKLISTED"].Visible = false;
            dgCustomerList.Columns["EVENT_DATE"].Visible = false;
        }
        else
        {
            //dgCustomerList.Columns["T_RELATION_EVENT_ID"].Visible = false;
            dgCustomerList.Columns["EVENT_DATE"].Visible = true;
            dgCustomerList.Columns["CODE"].Visible = true;
            dgCustomerList.Columns["IS_INVITED"].Visible = true;
            dgCustomerList.Columns["IS_ATTENDED"].Visible = true;
            dgCustomerList.Columns["IS_CONFIRMED"].Visible = true;
            dgCustomerList.Columns["IS_BLACKLISTED"].Visible = true;
        }
    }

    public void SendMailExample(UFTMailData uftMailData, String sxEmailType)
    {
        String sxSender = DBQuery.EmailSenderTable.GetRecentEmail();
        String sxAttachment = uftMailData.sxInvAttachmentPath;
        String sxBackground = uftMailData.sxInvAttachmentPath;
        Mailer mail = new Mailer();
        //mail.EmailSender = new System.Net.Mail.MailAddress("donot-reply@icp.lintasarta.co.id", "ICP Bots");
        mail.EmailSender = new System.Net.Mail.MailAddress(sxSender);
        mail.EmailSubject = uftMailData.sxEvent + " : " + uftMailData.sxCode;
        //mail.AddRecipient("diyani.janwir@lintasarta.co.id");
		//mail.AddRecipient("rinawati.daulay@lintasarta.co.id");
		//mail.AddRecipient("yoseph.yusnaedi@lintasarta.co.id");
		//mail.AddRecipient("arief@lintasmediadanawa.com");
		//mail.AddRecipient("diw@lintasarta.co.id");
		//mail.AddRecipient("anggita@lintasmediadanawa.com");
		//mail.AddRecipient("nova@lintasmediadanawa.com");
        mail.AddRecipient(uftMailData.sxEmail);
        mail.AddCC("forum@lintasarta.co.id");
        mail.AddBCC("bayuardi.rahmanto@lintasarta.co.id");
		mail.AddBCC("fajar@lintasmediadanawa.com");
		
        if (sxEmailType.ToUpper().Equals("EMBEDDED"))
        {
            mail.EmbeddedImage = sxBackground;
        }
        else if (sxEmailType.ToUpper().Equals("ATTACHMENT"))
        {
            mail.AddAttachment(sxAttachment);
        }
        else if (sxEmailType.ToUpper().Equals("BOTH"))
        {
            mail.EmbeddedImage = sxBackground;
            mail.AddAttachment(sxAttachment);
        }
        //mail.EmailHTMLBody = UFTManager.Build_HTMLMailBody(uftMailData);
        //mail.EmailPlainText = UFTManager.Build_PlainMailBody(uftMailData); 
		mail.EmailHTMLBody = DBQuery.EventTable.GetHTMLEmail(m_iEventId);
        mail.EmailPlainText = DBQuery.EventTable.GetPlainEmail(m_iEventId);
        mail.SendMail();
    }

    public static String GetInviteColumn(String sxId, String sxCustomerId, String sxStatus)
    {
        String sxOutput = String.Empty;
        if (sxStatus.ToUpper().Equals("Y"))
        {
            sxOutput = "-";
        }
        else
        {
            sxOutput = String.Format(
                "<a href=\"javascript:InviteGuest('{0}','{1}');\">Invite</a>",
                sxId, sxCustomerId);
        }
        return sxOutput;
    }
    public static String GetRejectColumn(String sxCustomerId, String sxId, String sxStatus)
    {
        String sxOutput = String.Empty;
        if (sxStatus.ToUpper().Equals("Y"))
        {
            sxOutput = "Rejected";
        }
        else
        {
            sxOutput = String.Format(
                "<a href=\"javascript:RejectGuest('{0}','{1}');\">REJECT</a>",
                sxId, sxCustomerId);
        }
        return sxOutput;
    }

    #endregion Custom Methods

    class CompanyTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            GridViewDataItemTemplateContainer gridContainer =
                (GridViewDataItemTemplateContainer)container;

            String sxCustID = gridContainer.Grid.GetRowValues(gridContainer.VisibleIndex,
                                "CUSTOMER_ID").ToString();
            String sxCompName = gridContainer.Grid.GetRowValues(gridContainer.VisibleIndex,
                                "COMPANY_NAME").ToString();
            String sxOutput = GridColumnManager.GetCompanyLinkColumn(
                                sxCustID, sxCompName);
            LiteralControl ltr = new LiteralControl(sxOutput);
            container.Controls.Add(ltr);
        }
    }
}
